package com.aphrodite.ui.widgets.barcode;

import java.util.Hashtable;
import java.util.Vector;

/**
 * Code 128 barcode module definitions.
 * 
 */
final class C128ModuleFactory {
	/**
	 * Specific module implementation that defines the Code 128 Code change
	 * character.
	 * 
	 */
	static class C128CodeChangeMod extends Module {
		private final int code;

		/**
		 * Constructs a code change module with the specified bars and character
		 * set.
		 * 
		 * @param bars
		 *            The bars to draw to encode the shift
		 * @param code
		 *            The character set that this module represents
		 */
		C128CodeChangeMod(int[] bars, int code) {
			super(bars);
			this.code = code;
		}

		/**
		 * Returns the character code set that this module represents.
		 * 
		 * @return The character set
		 */
		int getCode() {
			return code;
		}
	}
	/**
	 * Specific module implemetation that represents the Code 128 code shift
	 * character.
	 * 
	 */
	static class C128ShiftMod extends Module {

		/**
		 * Constructs a shift module with the specified bars.
		 * 
		 * @param bars
		 *            The bars to draw to encode the shift
		 */
		C128ShiftMod(int[] bars) {
			super(bars);
		}
	}
	private static final Vector A_KEYS = new Vector();
	private static final Hashtable A_SET = new Hashtable();
	private static final Vector B_KEYS = new Vector();
	private static final Hashtable B_SET = new Hashtable();

	private static final Vector C_KEYS = new Vector();

	private static final Hashtable C_SET = new Hashtable();

	// /CLOVER:ON

	static {
		initA();
		initB();
		initC();
	}

	/**
	 * Returns the index of the given character in the encoding tables. This is
	 * used when calculating the checksum.
	 * 
	 * @param key
	 *            The data character sequence to get the index for
	 * @param mode
	 *            The character set mode that is currently in use (A, B or C)
	 * @return The index for the given key
	 */
	static int getIndex(String key, int mode) {
		Vector keys = getKeys(mode);
		return keys.indexOf(key);
	}

	private static Vector getKeys(int mode) {
		switch (mode) {
		case Code128Barcode.A:
			return A_KEYS;
		case Code128Barcode.C:
			return C_KEYS;
		}
		return B_KEYS;
	}

	/**
	 * Returns the module that represents the specified character and character
	 * set.
	 * 
	 * @param key
	 *            The data character to get the encoding module for
	 * @param mode
	 *            The character set mode that is currently in use (A, B or C)
	 * @return The module that encodes the given char in the given character set
	 */
	static Module getModule(String key, int mode) {
		Module module = null;
		switch (mode) {
		case Code128Barcode.A:
			module = (Module) A_SET.get(key);
			break;
		case Code128Barcode.B:
			module = (Module) B_SET.get(key);
			break;
		case Code128Barcode.C:
			module = (Module) C_SET.get(key);
			break;
		}
		if (module != null) {
			module.setSymbol(key);
		}
		return module;
	}

	/**
	 * Returns the encoded module at the given index position. This is used to
	 * get the encoded checksum character.
	 * 
	 * @param index
	 *            The index to get the module for
	 * @param mode
	 *            The character set mode that is currently in use (A, B or C)
	 * @return The module at the specified index
	 */
	static Module getModuleForIndex(int index, int mode) {
		Vector keys = getKeys(mode);
		return getModule((String) keys.elementAt(index), mode);
	}

	/**
	 * Initialise the module definitions.
	 */
	private static void initA() {
		A_KEYS.addElement(" ");
		A_SET.put(" ", new Module(new int[] { 2, 1, 2, 2, 2, 2 }));
		A_KEYS.addElement("!");
		A_SET.put("!", new Module(new int[] { 2, 2, 2, 1, 2, 2 }));
		A_KEYS.addElement("\"");
		A_SET.put("\"", new Module(new int[] { 2, 2, 2, 2, 2, 1 }));
		A_KEYS.addElement("#");
		A_SET.put("#", new Module(new int[] { 1, 2, 1, 2, 2, 3 }));
		A_KEYS.addElement("$");
		A_SET.put("$", new Module(new int[] { 1, 2, 1, 3, 2, 2 }));
		A_KEYS.addElement("%");
		A_SET.put("%", new Module(new int[] { 1, 3, 1, 2, 2, 2 }));
		A_KEYS.addElement("&");
		A_SET.put("&", new Module(new int[] { 1, 2, 2, 2, 1, 3 }));
		A_KEYS.addElement("'");
		A_SET.put("'", new Module(new int[] { 1, 2, 2, 3, 1, 2 }));
		A_KEYS.addElement("(");
		A_SET.put("(", new Module(new int[] { 1, 3, 2, 2, 1, 2 }));
		A_KEYS.addElement(")");
		A_SET.put(")", new Module(new int[] { 2, 2, 1, 2, 1, 3 }));
		A_KEYS.addElement("*");
		A_SET.put("*", new Module(new int[] { 2, 2, 1, 3, 1, 2 }));
		A_KEYS.addElement("+");
		A_SET.put("+", new Module(new int[] { 2, 3, 1, 2, 1, 2 }));
		A_KEYS.addElement(",");
		A_SET.put(",", new Module(new int[] { 1, 1, 2, 2, 3, 2 }));
		A_KEYS.addElement("-");
		A_SET.put("-", new Module(new int[] { 1, 2, 2, 1, 3, 2 }));
		A_KEYS.addElement(".");
		A_SET.put(".", new Module(new int[] { 1, 2, 2, 2, 3, 1 }));
		A_KEYS.addElement("/");
		A_SET.put("/", new Module(new int[] { 1, 1, 3, 2, 2, 2 }));
		A_KEYS.addElement("0");
		A_SET.put("0", new Module(new int[] { 1, 2, 3, 1, 2, 2 }));
		A_KEYS.addElement("1");
		A_SET.put("1", new Module(new int[] { 1, 2, 3, 2, 2, 1 }));
		A_KEYS.addElement("2");
		A_SET.put("2", new Module(new int[] { 2, 2, 3, 2, 1, 1 }));
		A_KEYS.addElement("3");
		A_SET.put("3", new Module(new int[] { 2, 2, 1, 1, 3, 2 }));
		A_KEYS.addElement("4");
		A_SET.put("4", new Module(new int[] { 2, 2, 1, 2, 3, 1 }));
		A_KEYS.addElement("5");
		A_SET.put("5", new Module(new int[] { 2, 1, 3, 2, 1, 2 }));
		A_KEYS.addElement("6");
		A_SET.put("6", new Module(new int[] { 2, 2, 3, 1, 1, 2 }));
		A_KEYS.addElement("7");
		A_SET.put("7", new Module(new int[] { 3, 1, 2, 1, 3, 1 }));
		A_KEYS.addElement("8");
		A_SET.put("8", new Module(new int[] { 3, 1, 1, 2, 2, 2 }));
		A_KEYS.addElement("9");
		A_SET.put("9", new Module(new int[] { 3, 2, 1, 1, 2, 2 }));
		A_KEYS.addElement(":");
		A_SET.put(":", new Module(new int[] { 3, 2, 1, 2, 2, 1 }));
		A_KEYS.addElement(";");
		A_SET.put(";", new Module(new int[] { 3, 1, 2, 2, 1, 2 }));
		A_KEYS.addElement("<");
		A_SET.put("<", new Module(new int[] { 3, 2, 2, 1, 1, 2 }));
		A_KEYS.addElement("=");
		A_SET.put("=", new Module(new int[] { 3, 2, 2, 2, 1, 1 }));
		A_KEYS.addElement(">");
		A_SET.put(">", new Module(new int[] { 2, 1, 2, 1, 2, 3 }));
		A_KEYS.addElement("?");
		A_SET.put("?", new Module(new int[] { 2, 1, 2, 3, 2, 1 }));
		A_KEYS.addElement("@");
		A_SET.put("@", new Module(new int[] { 2, 3, 2, 1, 2, 1 }));
		A_KEYS.addElement("A");
		A_SET.put("A", new Module(new int[] { 1, 1, 1, 3, 2, 3 }));
		A_KEYS.addElement("B");
		A_SET.put("B", new Module(new int[] { 1, 3, 1, 1, 2, 3 }));
		A_KEYS.addElement("C");
		A_SET.put("C", new Module(new int[] { 1, 3, 1, 3, 2, 1 }));
		A_KEYS.addElement("D");
		A_SET.put("D", new Module(new int[] { 1, 1, 2, 3, 1, 3 }));
		A_KEYS.addElement("E");
		A_SET.put("E", new Module(new int[] { 1, 3, 2, 1, 1, 3 }));
		A_KEYS.addElement("F");
		A_SET.put("F", new Module(new int[] { 1, 3, 2, 3, 1, 1 }));
		A_KEYS.addElement("G");
		A_SET.put("G", new Module(new int[] { 2, 1, 1, 3, 1, 3 }));
		A_KEYS.addElement("H");
		A_SET.put("H", new Module(new int[] { 2, 3, 1, 1, 1, 3 }));
		A_KEYS.addElement("I");
		A_SET.put("I", new Module(new int[] { 2, 3, 1, 3, 1, 1 }));
		A_KEYS.addElement("J");
		A_SET.put("J", new Module(new int[] { 1, 1, 2, 1, 3, 3 }));
		A_KEYS.addElement("K");
		A_SET.put("K", new Module(new int[] { 1, 1, 2, 3, 3, 1 }));
		A_KEYS.addElement("L");
		A_SET.put("L", new Module(new int[] { 1, 3, 2, 1, 3, 1 }));
		A_KEYS.addElement("M");
		A_SET.put("M", new Module(new int[] { 1, 1, 3, 1, 2, 3 }));
		A_KEYS.addElement("N");
		A_SET.put("N", new Module(new int[] { 1, 1, 3, 3, 2, 1 }));
		A_KEYS.addElement("O");
		A_SET.put("O", new Module(new int[] { 1, 3, 3, 1, 2, 1 }));
		A_KEYS.addElement("P");
		A_SET.put("P", new Module(new int[] { 3, 1, 3, 1, 2, 1 }));
		A_KEYS.addElement("Q");
		A_SET.put("Q", new Module(new int[] { 2, 1, 1, 3, 3, 1 }));
		A_KEYS.addElement("R");
		A_SET.put("R", new Module(new int[] { 2, 3, 1, 1, 3, 1 }));
		A_KEYS.addElement("S");
		A_SET.put("S", new Module(new int[] { 2, 1, 3, 1, 1, 3 }));
		A_KEYS.addElement("T");
		A_SET.put("T", new Module(new int[] { 2, 1, 3, 3, 1, 1 }));
		A_KEYS.addElement("U");
		A_SET.put("U", new Module(new int[] { 2, 1, 3, 1, 3, 1 }));
		A_KEYS.addElement("V");
		A_SET.put("V", new Module(new int[] { 3, 1, 1, 1, 2, 3 }));
		A_KEYS.addElement("W");
		A_SET.put("W", new Module(new int[] { 3, 1, 1, 3, 2, 1 }));
		A_KEYS.addElement("X");
		A_SET.put("X", new Module(new int[] { 3, 3, 1, 1, 2, 1 }));
		A_KEYS.addElement("Y");
		A_SET.put("Y", new Module(new int[] { 3, 1, 2, 1, 1, 3 }));
		A_KEYS.addElement("Z");
		A_SET.put("Z", new Module(new int[] { 3, 1, 2, 3, 1, 1 }));
		A_KEYS.addElement("[");
		A_SET.put("[", new Module(new int[] { 3, 3, 2, 1, 1, 1 }));
		A_KEYS.addElement("\\");
		A_SET.put("\\", new Module(new int[] { 3, 1, 4, 1, 1, 1 }));
		A_KEYS.addElement("]");
		A_SET.put("]", new Module(new int[] { 2, 2, 1, 4, 1, 1 }));
		A_KEYS.addElement("^");
		A_SET.put("^", new Module(new int[] { 4, 3, 1, 1, 1, 1 }));
		A_KEYS.addElement("_");
		A_SET.put("_", new Module(new int[] { 1, 1, 1, 2, 2, 4 }));
		/* NUL */A_KEYS.addElement("\000");
		A_SET.put("\000", new Module(new int[] { 1, 1, 1, 4, 2, 2 }));
		/* SOH */A_KEYS.addElement("\001");
		A_SET.put("\001", new Module(new int[] { 1, 2, 1, 1, 2, 4 }));
		/* STX */A_KEYS.addElement("\002");
		A_SET.put("\002", new Module(new int[] { 1, 2, 1, 4, 2, 1 }));
		/* ETX */A_KEYS.addElement("\003");
		A_SET.put("\003", new Module(new int[] { 1, 4, 1, 1, 2, 2 }));
		/* EOT */A_KEYS.addElement("\004");
		A_SET.put("\004", new Module(new int[] { 1, 4, 1, 2, 2, 1 }));
		/* ENQ */A_KEYS.addElement("\005");
		A_SET.put("\005", new Module(new int[] { 1, 1, 2, 2, 1, 4 }));
		/* ACK */A_KEYS.addElement("\006");
		A_SET.put("\006", new Module(new int[] { 1, 1, 2, 4, 1, 2 }));
		/* BEL */A_KEYS.addElement("\007");
		A_SET.put("\007", new Module(new int[] { 1, 2, 2, 1, 1, 4 }));
		/* BS */A_KEYS.addElement("\010");
		A_SET.put("\010", new Module(new int[] { 1, 2, 2, 4, 1, 1 }));
		/* HT */A_KEYS.addElement("\011");
		A_SET.put("\011", new Module(new int[] { 1, 4, 2, 1, 1, 2 }));
		/* LF */A_KEYS.addElement("\012");
		A_SET.put("\012", new Module(new int[] { 1, 4, 2, 2, 1, 1 }));
		/* VT */A_KEYS.addElement("\013");
		A_SET.put("\013", new Module(new int[] { 2, 4, 1, 2, 1, 1 }));
		/* FF */A_KEYS.addElement("\014");
		A_SET.put("\014", new Module(new int[] { 2, 2, 1, 1, 1, 4 }));
		/* CR */A_KEYS.addElement("\015");
		A_SET.put("\015", new Module(new int[] { 4, 1, 3, 1, 1, 1 }));
		/* SO */A_KEYS.addElement("\016");
		A_SET.put("\016", new Module(new int[] { 2, 4, 1, 1, 1, 2 }));
		/* SI */A_KEYS.addElement("\017");
		A_SET.put("\017", new Module(new int[] { 1, 3, 4, 1, 1, 1 }));
		/* DLE */A_KEYS.addElement("\020");
		A_SET.put("\020", new Module(new int[] { 1, 1, 1, 2, 4, 2 }));
		/* DC1 */A_KEYS.addElement("\021");
		A_SET.put("\021", new Module(new int[] { 1, 2, 1, 1, 4, 2 }));
		/* DC2 */A_KEYS.addElement("\022");
		A_SET.put("\022", new Module(new int[] { 1, 2, 1, 2, 4, 1 }));
		/* DC3 */A_KEYS.addElement("\023");
		A_SET.put("\023", new Module(new int[] { 1, 1, 4, 2, 1, 2 }));
		/* DC4 */A_KEYS.addElement("\024");
		A_SET.put("\024", new Module(new int[] { 1, 2, 4, 1, 1, 2 }));
		/* NAK */A_KEYS.addElement("\025");
		A_SET.put("\025", new Module(new int[] { 1, 2, 4, 2, 1, 1 }));
		/* SYN */A_KEYS.addElement("\026");
		A_SET.put("\026", new Module(new int[] { 4, 1, 1, 2, 1, 2 }));
		/* ETB */A_KEYS.addElement("\027");
		A_SET.put("\027", new Module(new int[] { 4, 2, 1, 1, 1, 2 }));
		/* CAN */A_KEYS.addElement("\030");
		A_SET.put("\030", new Module(new int[] { 4, 2, 1, 2, 1, 1 }));
		/* EM */A_KEYS.addElement("\031");
		A_SET.put("\031", new Module(new int[] { 2, 1, 2, 1, 4, 1 }));
		/* SUB */A_KEYS.addElement("\032");
		A_SET.put("\032", new Module(new int[] { 2, 1, 4, 1, 2, 1 }));
		/* ESC */A_KEYS.addElement("\033");
		A_SET.put("\033", new Module(new int[] { 4, 1, 2, 1, 2, 1 }));
		/* FS */A_KEYS.addElement("\034");
		A_SET.put("\034", new Module(new int[] { 1, 1, 1, 1, 4, 3 }));
		/* GS */A_KEYS.addElement("\035");
		A_SET.put("\035", new Module(new int[] { 1, 1, 1, 3, 4, 1 }));
		/* RS */A_KEYS.addElement("\036");
		A_SET.put("\036", new Module(new int[] { 1, 3, 1, 1, 4, 1 }));
		/* US */A_KEYS.addElement("\037");
		A_SET.put("\037", new Module(new int[] { 1, 1, 4, 1, 1, 3 }));
		A_KEYS.addElement("\304");
		A_SET.put("\304", new Module(new int[] { 1, 1, 4, 3, 1, 1 })); // FNC3
		A_KEYS.addElement("\305");
		A_SET.put("\305", new Module(new int[] { 4, 1, 1, 1, 1, 3 })); // FNC2
		A_KEYS.addElement("\306");
		A_SET.put("\306", new C128ShiftMod(new int[] { 4, 1, 1, 3, 1, 1 })); // SHIFT
		A_KEYS.addElement("\307");
		A_SET.put("\307", new C128CodeChangeMod(new int[] { 1, 1, 3, 1, 4, 1 }, Code128Barcode.C)); // CODE
		// C
		A_KEYS.addElement("\310");
		A_SET.put("\310", new C128CodeChangeMod(new int[] { 1, 1, 4, 1, 3, 1 }, Code128Barcode.B)); // CODE
		// B
		A_KEYS.addElement("\311");
		A_SET.put("\311", new Module(new int[] { 3, 1, 1, 1, 4, 1 })); // FNC4
		A_KEYS.addElement("\312");
		A_SET.put("\312", new Module(new int[] { 4, 1, 1, 1, 3, 1 })); // FNC1
	}

	/**
	 * Initialise the module definitions.
	 */
	private static void initB() {
		B_KEYS.addElement(" ");
		B_SET.put(" ", new Module(new int[] { 2, 1, 2, 2, 2, 2 }));
		B_KEYS.addElement("!");
		B_SET.put("!", new Module(new int[] { 2, 2, 2, 1, 2, 2 }));
		B_KEYS.addElement("\"");
		B_SET.put("\"", new Module(new int[] { 2, 2, 2, 2, 2, 1 }));
		B_KEYS.addElement("#");
		B_SET.put("#", new Module(new int[] { 1, 2, 1, 2, 2, 3 }));
		B_KEYS.addElement("$");
		B_SET.put("$", new Module(new int[] { 1, 2, 1, 3, 2, 2 }));
		B_KEYS.addElement("%");
		B_SET.put("%", new Module(new int[] { 1, 3, 1, 2, 2, 2 }));
		B_KEYS.addElement("&");
		B_SET.put("&", new Module(new int[] { 1, 2, 2, 2, 1, 3 }));
		B_KEYS.addElement("'");
		B_SET.put("'", new Module(new int[] { 1, 2, 2, 3, 1, 2 }));
		B_KEYS.addElement("(");
		B_SET.put("(", new Module(new int[] { 1, 3, 2, 2, 1, 2 }));
		B_KEYS.addElement(")");
		B_SET.put(")", new Module(new int[] { 2, 2, 1, 2, 1, 3 }));
		B_KEYS.addElement("*");
		B_SET.put("*", new Module(new int[] { 2, 2, 1, 3, 1, 2 }));
		B_KEYS.addElement("+");
		B_SET.put("+", new Module(new int[] { 2, 3, 1, 2, 1, 2 }));
		B_KEYS.addElement(",");
		B_SET.put(",", new Module(new int[] { 1, 1, 2, 2, 3, 2 }));
		B_KEYS.addElement("-");
		B_SET.put("-", new Module(new int[] { 1, 2, 2, 1, 3, 2 }));
		B_KEYS.addElement(".");
		B_SET.put(".", new Module(new int[] { 1, 2, 2, 2, 3, 1 }));
		B_KEYS.addElement("/");
		B_SET.put("/", new Module(new int[] { 1, 1, 3, 2, 2, 2 }));
		B_KEYS.addElement("0");
		B_SET.put("0", new Module(new int[] { 1, 2, 3, 1, 2, 2 }));
		B_KEYS.addElement("1");
		B_SET.put("1", new Module(new int[] { 1, 2, 3, 2, 2, 1 }));
		B_KEYS.addElement("2");
		B_SET.put("2", new Module(new int[] { 2, 2, 3, 2, 1, 1 }));
		B_KEYS.addElement("3");
		B_SET.put("3", new Module(new int[] { 2, 2, 1, 1, 3, 2 }));
		B_KEYS.addElement("4");
		B_SET.put("4", new Module(new int[] { 2, 2, 1, 2, 3, 1 }));
		B_KEYS.addElement("5");
		B_SET.put("5", new Module(new int[] { 2, 1, 3, 2, 1, 2 }));
		B_KEYS.addElement("6");
		B_SET.put("6", new Module(new int[] { 2, 2, 3, 1, 1, 2 }));
		B_KEYS.addElement("7");
		B_SET.put("7", new Module(new int[] { 3, 1, 2, 1, 3, 1 }));
		B_KEYS.addElement("8");
		B_SET.put("8", new Module(new int[] { 3, 1, 1, 2, 2, 2 }));
		B_KEYS.addElement("9");
		B_SET.put("9", new Module(new int[] { 3, 2, 1, 1, 2, 2 }));
		B_KEYS.addElement(":");
		B_SET.put(":", new Module(new int[] { 3, 2, 1, 2, 2, 1 }));
		B_KEYS.addElement(";");
		B_SET.put(";", new Module(new int[] { 3, 1, 2, 2, 1, 2 }));
		B_KEYS.addElement("<");
		B_SET.put("<", new Module(new int[] { 3, 2, 2, 1, 1, 2 }));
		B_KEYS.addElement("=");
		B_SET.put("=", new Module(new int[] { 3, 2, 2, 2, 1, 1 }));
		B_KEYS.addElement(">");
		B_SET.put(">", new Module(new int[] { 2, 1, 2, 1, 2, 3 }));
		B_KEYS.addElement("?");
		B_SET.put("?", new Module(new int[] { 2, 1, 2, 3, 2, 1 }));
		B_KEYS.addElement("@");
		B_SET.put("@", new Module(new int[] { 2, 3, 2, 1, 2, 1 }));
		B_KEYS.addElement("A");
		B_SET.put("A", new Module(new int[] { 1, 1, 1, 3, 2, 3 }));
		B_KEYS.addElement("B");
		B_SET.put("B", new Module(new int[] { 1, 3, 1, 1, 2, 3 }));
		B_KEYS.addElement("C");
		B_SET.put("C", new Module(new int[] { 1, 3, 1, 3, 2, 1 }));
		B_KEYS.addElement("D");
		B_SET.put("D", new Module(new int[] { 1, 1, 2, 3, 1, 3 }));
		B_KEYS.addElement("E");
		B_SET.put("E", new Module(new int[] { 1, 3, 2, 1, 1, 3 }));
		B_KEYS.addElement("F");
		B_SET.put("F", new Module(new int[] { 1, 3, 2, 3, 1, 1 }));
		B_KEYS.addElement("G");
		B_SET.put("G", new Module(new int[] { 2, 1, 1, 3, 1, 3 }));
		B_KEYS.addElement("H");
		B_SET.put("H", new Module(new int[] { 2, 3, 1, 1, 1, 3 }));
		B_KEYS.addElement("I");
		B_SET.put("I", new Module(new int[] { 2, 3, 1, 3, 1, 1 }));
		B_KEYS.addElement("J");
		B_SET.put("J", new Module(new int[] { 1, 1, 2, 1, 3, 3 }));
		B_KEYS.addElement("K");
		B_SET.put("K", new Module(new int[] { 1, 1, 2, 3, 3, 1 }));
		B_KEYS.addElement("L");
		B_SET.put("L", new Module(new int[] { 1, 3, 2, 1, 3, 1 }));
		B_KEYS.addElement("M");
		B_SET.put("M", new Module(new int[] { 1, 1, 3, 1, 2, 3 }));
		B_KEYS.addElement("N");
		B_SET.put("N", new Module(new int[] { 1, 1, 3, 3, 2, 1 }));
		B_KEYS.addElement("O");
		B_SET.put("O", new Module(new int[] { 1, 3, 3, 1, 2, 1 }));
		B_KEYS.addElement("P");
		B_SET.put("P", new Module(new int[] { 3, 1, 3, 1, 2, 1 }));
		B_KEYS.addElement("Q");
		B_SET.put("Q", new Module(new int[] { 2, 1, 1, 3, 3, 1 }));
		B_KEYS.addElement("R");
		B_SET.put("R", new Module(new int[] { 2, 3, 1, 1, 3, 1 }));
		B_KEYS.addElement("S");
		B_SET.put("S", new Module(new int[] { 2, 1, 3, 1, 1, 3 }));
		B_KEYS.addElement("T");
		B_SET.put("T", new Module(new int[] { 2, 1, 3, 3, 1, 1 }));
		B_KEYS.addElement("U");
		B_SET.put("U", new Module(new int[] { 2, 1, 3, 1, 3, 1 }));
		B_KEYS.addElement("V");
		B_SET.put("V", new Module(new int[] { 3, 1, 1, 1, 2, 3 }));
		B_KEYS.addElement("W");
		B_SET.put("W", new Module(new int[] { 3, 1, 1, 3, 2, 1 }));
		B_KEYS.addElement("X");
		B_SET.put("X", new Module(new int[] { 3, 3, 1, 1, 2, 1 }));
		B_KEYS.addElement("Y");
		B_SET.put("Y", new Module(new int[] { 3, 1, 2, 1, 1, 3 }));
		B_KEYS.addElement("Z");
		B_SET.put("Z", new Module(new int[] { 3, 1, 2, 3, 1, 1 }));
		B_KEYS.addElement("[");
		B_SET.put("[", new Module(new int[] { 3, 3, 2, 1, 1, 1 }));
		B_KEYS.addElement("\\");
		B_SET.put("\\", new Module(new int[] { 3, 1, 4, 1, 1, 1 }));
		B_KEYS.addElement("]");
		B_SET.put("]", new Module(new int[] { 2, 2, 1, 4, 1, 1 }));
		B_KEYS.addElement("^");
		B_SET.put("^", new Module(new int[] { 4, 3, 1, 1, 1, 1 }));
		B_KEYS.addElement("_");
		B_SET.put("_", new Module(new int[] { 1, 1, 1, 2, 2, 4 }));
		B_KEYS.addElement("`");
		B_SET.put("`", new Module(new int[] { 1, 1, 1, 4, 2, 2 }));
		B_KEYS.addElement("a");
		B_SET.put("a", new Module(new int[] { 1, 2, 1, 1, 2, 4 }));
		B_KEYS.addElement("b");
		B_SET.put("b", new Module(new int[] { 1, 2, 1, 4, 2, 1 }));
		B_KEYS.addElement("c");
		B_SET.put("c", new Module(new int[] { 1, 4, 1, 1, 2, 2 }));
		B_KEYS.addElement("d");
		B_SET.put("d", new Module(new int[] { 1, 4, 1, 2, 2, 1 }));
		B_KEYS.addElement("e");
		B_SET.put("e", new Module(new int[] { 1, 1, 2, 2, 1, 4 }));
		B_KEYS.addElement("f");
		B_SET.put("f", new Module(new int[] { 1, 1, 2, 4, 1, 2 }));
		B_KEYS.addElement("g");
		B_SET.put("g", new Module(new int[] { 1, 2, 2, 1, 1, 4 }));
		B_KEYS.addElement("h");
		B_SET.put("h", new Module(new int[] { 1, 2, 2, 4, 1, 1 }));
		B_KEYS.addElement("i");
		B_SET.put("i", new Module(new int[] { 1, 4, 2, 1, 1, 2 }));
		B_KEYS.addElement("j");
		B_SET.put("j", new Module(new int[] { 1, 4, 2, 2, 1, 1 }));
		B_KEYS.addElement("k");
		B_SET.put("k", new Module(new int[] { 2, 4, 1, 2, 1, 1 }));
		B_KEYS.addElement("l");
		B_SET.put("l", new Module(new int[] { 2, 2, 1, 1, 1, 4 }));
		B_KEYS.addElement("m");
		B_SET.put("m", new Module(new int[] { 4, 1, 3, 1, 1, 1 }));
		B_KEYS.addElement("n");
		B_SET.put("n", new Module(new int[] { 2, 4, 1, 1, 1, 2 }));
		B_KEYS.addElement("o");
		B_SET.put("o", new Module(new int[] { 1, 3, 4, 1, 1, 1 }));
		B_KEYS.addElement("p");
		B_SET.put("p", new Module(new int[] { 1, 1, 1, 2, 4, 2 }));
		B_KEYS.addElement("q");
		B_SET.put("q", new Module(new int[] { 1, 2, 1, 1, 4, 2 }));
		B_KEYS.addElement("r");
		B_SET.put("r", new Module(new int[] { 1, 2, 1, 2, 4, 1 }));
		B_KEYS.addElement("s");
		B_SET.put("s", new Module(new int[] { 1, 1, 4, 2, 1, 2 }));
		B_KEYS.addElement("t");
		B_SET.put("t", new Module(new int[] { 1, 2, 4, 1, 1, 2 }));
		B_KEYS.addElement("u");
		B_SET.put("u", new Module(new int[] { 1, 2, 4, 2, 1, 1 }));
		B_KEYS.addElement("v");
		B_SET.put("v", new Module(new int[] { 4, 1, 1, 2, 1, 2 }));
		B_KEYS.addElement("w");
		B_SET.put("w", new Module(new int[] { 4, 2, 1, 1, 1, 2 }));
		B_KEYS.addElement("x");
		B_SET.put("x", new Module(new int[] { 4, 2, 1, 2, 1, 1 }));
		B_KEYS.addElement("y");
		B_SET.put("y", new Module(new int[] { 2, 1, 2, 1, 4, 1 }));
		B_KEYS.addElement("z");
		B_SET.put("z", new Module(new int[] { 2, 1, 4, 1, 2, 1 }));
		B_KEYS.addElement("{");
		B_SET.put("{", new Module(new int[] { 4, 1, 2, 1, 2, 1 }));
		B_KEYS.addElement("|");
		B_SET.put("|", new Module(new int[] { 1, 1, 1, 1, 4, 3 }));
		B_KEYS.addElement("}");
		B_SET.put("}", new Module(new int[] { 1, 1, 1, 3, 4, 1 }));
		B_KEYS.addElement("~");
		B_SET.put("~", new Module(new int[] { 1, 3, 1, 1, 4, 1 }));
		B_KEYS.addElement("\303");
		B_SET.put("\303", new Module(new int[] { 1, 1, 4, 1, 1, 3 })); // DEL
		// 10111101000
		B_KEYS.addElement("\304");
		B_SET.put("\304", new Module(new int[] { 1, 1, 4, 3, 1, 1 }));
		B_KEYS.addElement("\305");
		B_SET.put("\305", new Module(new int[] { 4, 1, 1, 1, 1, 3 }));
		B_KEYS.addElement("\306");
		B_SET.put("\306", new C128ShiftMod(new int[] { 4, 1, 1, 3, 1, 1 })); // SHIFT
		B_KEYS.addElement("\307");
		B_SET.put("\307", new C128CodeChangeMod(new int[] { 1, 1, 3, 1, 4, 1 }, Code128Barcode.C)); // CODE
		// C
		B_KEYS.addElement("\310");
		B_SET.put("\310", new Module(new int[] { 1, 1, 4, 1, 3, 1 }));
		B_KEYS.addElement("\311");
		B_SET.put("\311", new C128CodeChangeMod(new int[] { 3, 1, 1, 1, 4, 1 }, Code128Barcode.A)); // CODE
		// A
		B_KEYS.addElement("\312");
		B_SET.put("\312", new Module(new int[] { 4, 1, 1, 1, 3, 1 }));
	}

	/**
	 * Initialise the module definitions.
	 */
	private static void initC() {
		C_KEYS.addElement("00");
		C_SET.put("00", new Module(new int[] { 2, 1, 2, 2, 2, 2 }));
		C_KEYS.addElement("01");
		C_SET.put("01", new Module(new int[] { 2, 2, 2, 1, 2, 2 }));
		C_KEYS.addElement("02");
		C_SET.put("02", new Module(new int[] { 2, 2, 2, 2, 2, 1 }));
		C_KEYS.addElement("03");
		C_SET.put("03", new Module(new int[] { 1, 2, 1, 2, 2, 3 }));
		C_KEYS.addElement("04");
		C_SET.put("04", new Module(new int[] { 1, 2, 1, 3, 2, 2 }));
		C_KEYS.addElement("05");
		C_SET.put("05", new Module(new int[] { 1, 3, 1, 2, 2, 2 }));
		C_KEYS.addElement("06");
		C_SET.put("06", new Module(new int[] { 1, 2, 2, 2, 1, 3 }));
		C_KEYS.addElement("07");
		C_SET.put("07", new Module(new int[] { 1, 2, 2, 3, 1, 2 }));
		C_KEYS.addElement("08");
		C_SET.put("08", new Module(new int[] { 1, 3, 2, 2, 1, 2 }));
		C_KEYS.addElement("09");
		C_SET.put("09", new Module(new int[] { 2, 2, 1, 2, 1, 3 }));
		C_KEYS.addElement("10");
		C_SET.put("10", new Module(new int[] { 2, 2, 1, 3, 1, 2 }));
		C_KEYS.addElement("11");
		C_SET.put("11", new Module(new int[] { 2, 3, 1, 2, 1, 2 }));
		C_KEYS.addElement("12");
		C_SET.put("12", new Module(new int[] { 1, 1, 2, 2, 3, 2 }));
		C_KEYS.addElement("13");
		C_SET.put("13", new Module(new int[] { 1, 2, 2, 1, 3, 2 }));
		C_KEYS.addElement("14");
		C_SET.put("14", new Module(new int[] { 1, 2, 2, 2, 3, 1 }));
		C_KEYS.addElement("15");
		C_SET.put("15", new Module(new int[] { 1, 1, 3, 2, 2, 2 }));
		C_KEYS.addElement("16");
		C_SET.put("16", new Module(new int[] { 1, 2, 3, 1, 2, 2 }));
		C_KEYS.addElement("17");
		C_SET.put("17", new Module(new int[] { 1, 2, 3, 2, 2, 1 }));
		C_KEYS.addElement("18");
		C_SET.put("18", new Module(new int[] { 2, 2, 3, 2, 1, 1 }));
		C_KEYS.addElement("19");
		C_SET.put("19", new Module(new int[] { 2, 2, 1, 1, 3, 2 }));
		C_KEYS.addElement("20");
		C_SET.put("20", new Module(new int[] { 2, 2, 1, 2, 3, 1 }));
		C_KEYS.addElement("21");
		C_SET.put("21", new Module(new int[] { 2, 1, 3, 2, 1, 2 }));
		C_KEYS.addElement("22");
		C_SET.put("22", new Module(new int[] { 2, 2, 3, 1, 1, 2 }));
		C_KEYS.addElement("23");
		C_SET.put("23", new Module(new int[] { 3, 1, 2, 1, 3, 1 }));
		C_KEYS.addElement("24");
		C_SET.put("24", new Module(new int[] { 3, 1, 1, 2, 2, 2 }));
		C_KEYS.addElement("25");
		C_SET.put("25", new Module(new int[] { 3, 2, 1, 1, 2, 2 }));
		C_KEYS.addElement("26");
		C_SET.put("26", new Module(new int[] { 3, 2, 1, 2, 2, 1 }));
		C_KEYS.addElement("27");
		C_SET.put("27", new Module(new int[] { 3, 1, 2, 2, 1, 2 }));
		C_KEYS.addElement("28");
		C_SET.put("28", new Module(new int[] { 3, 2, 2, 1, 1, 2 }));
		C_KEYS.addElement("29");
		C_SET.put("29", new Module(new int[] { 3, 2, 2, 2, 1, 1 }));
		C_KEYS.addElement("30");
		C_SET.put("30", new Module(new int[] { 2, 1, 2, 1, 2, 3 }));
		C_KEYS.addElement("31");
		C_SET.put("31", new Module(new int[] { 2, 1, 2, 3, 2, 1 }));
		C_KEYS.addElement("32");
		C_SET.put("32", new Module(new int[] { 2, 3, 2, 1, 2, 1 }));
		C_KEYS.addElement("33");
		C_SET.put("33", new Module(new int[] { 1, 1, 1, 3, 2, 3 }));
		C_KEYS.addElement("34");
		C_SET.put("34", new Module(new int[] { 1, 3, 1, 1, 2, 3 }));
		C_KEYS.addElement("35");
		C_SET.put("35", new Module(new int[] { 1, 3, 1, 3, 2, 1 }));
		C_KEYS.addElement("36");
		C_SET.put("36", new Module(new int[] { 1, 1, 2, 3, 1, 3 }));
		C_KEYS.addElement("37");
		C_SET.put("37", new Module(new int[] { 1, 3, 2, 1, 1, 3 }));
		C_KEYS.addElement("38");
		C_SET.put("38", new Module(new int[] { 1, 3, 2, 3, 1, 1 }));
		C_KEYS.addElement("39");
		C_SET.put("39", new Module(new int[] { 2, 1, 1, 3, 1, 3 }));
		C_KEYS.addElement("40");
		C_SET.put("40", new Module(new int[] { 2, 3, 1, 1, 1, 3 }));
		C_KEYS.addElement("41");
		C_SET.put("41", new Module(new int[] { 2, 3, 1, 3, 1, 1 }));
		C_KEYS.addElement("42");
		C_SET.put("42", new Module(new int[] { 1, 1, 2, 1, 3, 3 }));
		C_KEYS.addElement("43");
		C_SET.put("43", new Module(new int[] { 1, 1, 2, 3, 3, 1 }));
		C_KEYS.addElement("44");
		C_SET.put("44", new Module(new int[] { 1, 3, 2, 1, 3, 1 }));
		C_KEYS.addElement("45");
		C_SET.put("45", new Module(new int[] { 1, 1, 3, 1, 2, 3 }));
		C_KEYS.addElement("46");
		C_SET.put("46", new Module(new int[] { 1, 1, 3, 3, 2, 1 }));
		C_KEYS.addElement("47");
		C_SET.put("47", new Module(new int[] { 1, 3, 3, 1, 2, 1 }));
		C_KEYS.addElement("48");
		C_SET.put("48", new Module(new int[] { 3, 1, 3, 1, 2, 1 }));
		C_KEYS.addElement("49");
		C_SET.put("49", new Module(new int[] { 2, 1, 1, 3, 3, 1 }));
		C_KEYS.addElement("50");
		C_SET.put("50", new Module(new int[] { 2, 3, 1, 1, 3, 1 }));
		C_KEYS.addElement("51");
		C_SET.put("51", new Module(new int[] { 2, 1, 3, 1, 1, 3 }));
		C_KEYS.addElement("52");
		C_SET.put("52", new Module(new int[] { 2, 1, 3, 3, 1, 1 }));
		C_KEYS.addElement("53");
		C_SET.put("53", new Module(new int[] { 2, 1, 3, 1, 3, 1 }));
		C_KEYS.addElement("54");
		C_SET.put("54", new Module(new int[] { 3, 1, 1, 1, 2, 3 }));
		C_KEYS.addElement("55");
		C_SET.put("55", new Module(new int[] { 3, 1, 1, 3, 2, 1 }));
		C_KEYS.addElement("56");
		C_SET.put("56", new Module(new int[] { 3, 3, 1, 1, 2, 1 }));
		C_KEYS.addElement("57");
		C_SET.put("57", new Module(new int[] { 3, 1, 2, 1, 1, 3 }));
		C_KEYS.addElement("58");
		C_SET.put("58", new Module(new int[] { 3, 1, 2, 3, 1, 1 }));
		C_KEYS.addElement("59");
		C_SET.put("59", new Module(new int[] { 3, 3, 2, 1, 1, 1 }));
		C_KEYS.addElement("60");
		C_SET.put("60", new Module(new int[] { 3, 1, 4, 1, 1, 1 }));
		C_KEYS.addElement("61");
		C_SET.put("61", new Module(new int[] { 2, 2, 1, 4, 1, 1 }));
		C_KEYS.addElement("62");
		C_SET.put("62", new Module(new int[] { 4, 3, 1, 1, 1, 1 }));
		C_KEYS.addElement("63");
		C_SET.put("63", new Module(new int[] { 1, 1, 1, 2, 2, 4 }));
		C_KEYS.addElement("64");
		C_SET.put("64", new Module(new int[] { 1, 1, 1, 4, 2, 2 }));
		C_KEYS.addElement("65");
		C_SET.put("65", new Module(new int[] { 1, 2, 1, 1, 2, 4 }));
		C_KEYS.addElement("66");
		C_SET.put("66", new Module(new int[] { 1, 2, 1, 4, 2, 1 }));
		C_KEYS.addElement("67");
		C_SET.put("67", new Module(new int[] { 1, 4, 1, 1, 2, 2 }));
		C_KEYS.addElement("68");
		C_SET.put("68", new Module(new int[] { 1, 4, 1, 2, 2, 1 }));
		C_KEYS.addElement("69");
		C_SET.put("69", new Module(new int[] { 1, 1, 2, 2, 1, 4 }));
		C_KEYS.addElement("70");
		C_SET.put("70", new Module(new int[] { 1, 1, 2, 4, 1, 2 }));
		C_KEYS.addElement("71");
		C_SET.put("71", new Module(new int[] { 1, 2, 2, 1, 1, 4 }));
		C_KEYS.addElement("72");
		C_SET.put("72", new Module(new int[] { 1, 2, 2, 4, 1, 1 }));
		C_KEYS.addElement("73");
		C_SET.put("73", new Module(new int[] { 1, 4, 2, 1, 1, 2 }));
		C_KEYS.addElement("74");
		C_SET.put("74", new Module(new int[] { 1, 4, 2, 2, 1, 1 }));
		C_KEYS.addElement("75");
		C_SET.put("75", new Module(new int[] { 2, 4, 1, 2, 1, 1 }));
		C_KEYS.addElement("76");
		C_SET.put("76", new Module(new int[] { 2, 2, 1, 1, 1, 4 }));
		C_KEYS.addElement("77");
		C_SET.put("77", new Module(new int[] { 4, 1, 3, 1, 1, 1 }));
		C_KEYS.addElement("78");
		C_SET.put("78", new Module(new int[] { 2, 4, 1, 1, 1, 2 }));
		C_KEYS.addElement("79");
		C_SET.put("79", new Module(new int[] { 1, 3, 4, 1, 1, 1 }));
		C_KEYS.addElement("80");
		C_SET.put("80", new Module(new int[] { 1, 1, 1, 2, 4, 2 }));
		C_KEYS.addElement("81");
		C_SET.put("81", new Module(new int[] { 1, 2, 1, 1, 4, 2 }));
		C_KEYS.addElement("82");
		C_SET.put("82", new Module(new int[] { 1, 2, 1, 2, 4, 1 }));
		C_KEYS.addElement("83");
		C_SET.put("83", new Module(new int[] { 1, 1, 4, 2, 1, 2 }));
		C_KEYS.addElement("84");
		C_SET.put("84", new Module(new int[] { 1, 2, 4, 1, 1, 2 }));
		C_KEYS.addElement("85");
		C_SET.put("85", new Module(new int[] { 1, 2, 4, 2, 1, 1 }));
		C_KEYS.addElement("86");
		C_SET.put("86", new Module(new int[] { 4, 1, 1, 2, 1, 2 }));
		C_KEYS.addElement("87");
		C_SET.put("87", new Module(new int[] { 4, 2, 1, 1, 1, 2 }));
		C_KEYS.addElement("88");
		C_SET.put("88", new Module(new int[] { 4, 2, 1, 2, 1, 1 }));
		C_KEYS.addElement("89");
		C_SET.put("89", new Module(new int[] { 2, 1, 2, 1, 4, 1 }));
		C_KEYS.addElement("90");
		C_SET.put("90", new Module(new int[] { 2, 1, 4, 1, 2, 1 }));
		C_KEYS.addElement("91");
		C_SET.put("91", new Module(new int[] { 4, 1, 2, 1, 2, 1 }));
		C_KEYS.addElement("92");
		C_SET.put("92", new Module(new int[] { 1, 1, 1, 1, 4, 3 }));
		C_KEYS.addElement("93");
		C_SET.put("93", new Module(new int[] { 1, 1, 1, 3, 4, 1 }));
		C_KEYS.addElement("94");
		C_SET.put("94", new Module(new int[] { 1, 3, 1, 1, 4, 1 }));
		C_KEYS.addElement("95");
		C_SET.put("95", new Module(new int[] { 1, 1, 4, 1, 1, 3 }));
		C_KEYS.addElement("96");
		C_SET.put("96", new Module(new int[] { 1, 1, 4, 3, 1, 1 }));
		C_KEYS.addElement("97");
		C_SET.put("97", new Module(new int[] { 4, 1, 1, 1, 1, 3 }));
		C_KEYS.addElement("98");
		C_SET.put("98", new Module(new int[] { 4, 1, 1, 3, 1, 1 }));
		C_KEYS.addElement("99");
		C_SET.put("99", new Module(new int[] { 1, 1, 3, 1, 4, 1 }));
		C_KEYS.addElement("\310");
		C_SET.put("\310", new C128CodeChangeMod(new int[] { 1, 1, 4, 1, 3, 1 }, Code128Barcode.B)); // CODE
		// B
		C_KEYS.addElement("\311");
		C_SET.put("\311", new C128CodeChangeMod(new int[] { 3, 1, 1, 1, 4, 1 }, Code128Barcode.A)); // CODE
		// A
		C_KEYS.addElement("\312");
		C_SET.put("\312", new Module(new int[] { 4, 1, 1, 1, 3, 1 }));
	}

	// /CLOVER:OFF
	/**
	 * Cannot construct.
	 */
	private C128ModuleFactory() {}
}
